<template>

  <div align="center">
    <div @click="goBack">
      <el-page-header icon="el-icon-arrow-left" ></el-page-header>

    </div>
    <div align="center" style="height: 690px;width: 690px">


      <br>
      <el-carousel :interval="4000" type="card" height="200px">
        <el-carousel-item v-for="item in 6" :key="item">
          <h3>图片待填充</h3>
          <h3 class="medium">{{ item }}</h3>
        </el-carousel-item>
      </el-carousel>
      <br>

      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="帐号" prop="username">
          <el-input type="text" v-model="ruleForm.username"  autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="邦定的手机号" prop="phone">
          <el-input type="text" v-model.number="ruleForm.phone"    ></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="password">
          <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>


</template>

<script>
export default {
  inject:['reload'],
  data() {
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('新密码不能为空'));
      }else{
        callback();
      }

    };
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入帐号'));
      } else {
        if (this.ruleForm.username !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {

      if (value === '') {
        callback(new Error('手机号不能为空'));
      } else {
        if (this.ruleForm.username !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }

    };
    return {
      ruleForm: {
        username: '',
        phone: '',
        password: ''
      },
      rules: {
        username: [
          { validator: validatePass, trigger: 'blur' }
        ],
        phone: [
          { validator: validatePass2, trigger: 'blur' }
        ],
        password: [
          { validator: checkAge, trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    aler(){
      alert("123");
    },
    goBack() {
      this.$router.replace("/")
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {

         axios({
           url:"http://82.156.197.128:8085/user/forgetPassowrd",
           method:"POST",
           params:{
             "username":this.ruleForm.username,
             "phone":this.ruleForm.phone,
             "password":this.ruleForm.password
           }
         }).then((resp)=>{
           if (resp.data==='null'){
             this.$notify.error({
               title:"错误",
               message:"用户名为空~"
             })
           }else if (resp.data==='error'){
             this.$notify.error({
               title:"错误",
               message:"绑定的手机号不匹配~"
             })
           }else {
             this.$notify.success({
               title:"成功",
               message:"密码修改成功~"
             })
            setTimeout(this.$router.push("/"),800)
           }
         })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}
</style>
